﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CardInChina.Data.Entity.Entity;

namespace CardInChina.Data.Entity.Interface
{
    public class CardService
    {
        public IEnumerable<Card> GetSalePromotionCards(int top)
        {
            using (CICEntities db = new CICEntities())
            {
                return db.Cards
                    .Include("OfCardInfo")
                    .Where(p => p.OnSale == true && p.IsSoldPromotion == 1)
                    .OrderBy(p => p.CardMemo)
                    .Take(top)
                    .ToArray();
            }
        }

        public Card GetCardEntityByCardID(int cardId)
        {
            using (CICEntities db = new CICEntities())
            {
                return db.Cards.FirstOrDefault(p => p.CardID == cardId);
            }
        }

        public Card GetCardEntityByCardKey(string cardKey)
        {
            using (CICEntities db = new CICEntities())
            {
                return db.Cards.FirstOrDefault(p => p.CardKey == cardKey);
            }
        }
       
    }
}
